package com.yayun.merchant.controller;

import com.yayun.common.annotation.Log;
import com.yayun.common.core.controller.BaseController;
import com.yayun.common.core.domain.AjaxResult;
import com.yayun.common.core.page.TableDataInfo;
import com.yayun.common.enums.BusinessType;
import com.yayun.common.utils.SecurityUtils;
import com.yayun.merchant.domain.AuctionRecord;
import com.yayun.merchant.service.IAuctionRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/merchant/auction/record")
public class AuctionRecordController extends BaseController {
    @Autowired
    private IAuctionRecordService auctionRecordService;

    /**
     * 查询竞拍记录列表
     */
    @PreAuthorize("@ss.hasPermi('merchant:auction:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(AuctionRecord auctionRecord) {
        startPage();
        List<AuctionRecord> list = auctionRecordService.selectAuctionRecordList(auctionRecord);
        return getDataTable(list);
    }

    /**
     * 获取竞拍记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('merchant:auction:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(auctionRecordService.selectAuctionRecordById(id));
    }

    /**
     * 删除竞拍记录
     */
    @PreAuthorize("@ss.hasPermi('merchant:auction:record:remove')")
    @Log(title = "竞拍记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(auctionRecordService.deleteAuctionRecordByIds(ids));
    }

    /**
     * 查询当前用户的竞拍记录
     */
    @GetMapping("/my")
    public TableDataInfo myRecords() {
        startPage();
        List<AuctionRecord> list = auctionRecordService.selectUserAuctionRecords(SecurityUtils.getUserId());
        return getDataTable(list);
    }
} 